//
//  SimpleTest.swift
//  ArchitectGenerics
//
//  Created by 姚胜龙 on 2017/6/22.
//  Copyright © 2017年 姚胜龙. All rights reserved.
//

import UIKit

class SimpleTest: NSObject {

    class func arrayTest() {
        //Array

        var someInt = Array<Int>()
        someInt.append(3)
//
//        let someInts: [Int] = Array(repeating: 0, count: 3)
//        someInts.index(of: 0)

//        let someInts1 = Array(repeating: 2, count: 10)
//        let somenInts2 = Array(repeating: 100, count: 20)
//
//        let someInts3 = someInts1 + somenInts2
//        print(someInts3)
        //字面量初始化数组
        var names:[String] = ["xiaoming","mimi","dabao","shuiniu"]
        //print(names)
        names += ["lili"]
        //names("flor")
        //相当于names[2]="heiniu"&names[3] = "feiniu"
        names[2...3] = ["heiniu","feiniu"]
        //print(names)

        names.insert("xiaomi", at: 0)
        print(names)
    }

    //集合测试
    class func setTest() {

        var letters = Set<Character>()
        letters.insert("a")
        //print(letters)

        var favoriteGenres: Set<String> = ["Rock", "Classical", "Hip hop"]
        favoriteGenres.insert("Pop")
        //print(favoriteGenres)

        if favoriteGenres.isEmpty {
            //print("集合为空")
        }
        else {
            //print("集合不为空")
        }

        if favoriteGenres.contains("Rock") {
            //print("集合包含Rock")
        }
        else {
            //print("集合不包含Rock")
        }

        //≠≠≠≠≠≠≠≠≠≠≠≠≠≠集合运算≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠≠
//        let setA:Set<Int> = [1,2,3,4,5]
//        let setB:Set<Int> = [4,5,6,7,8,9]
//        let setResult1 = setA.subtracting(setB)
//        print(setResult1);
//        let setResult2 = setA.intersection(setB)
//        print(setResult2);
//        let setResult3 = setA.union(setB)
//        print(setResult3);
//        let setResult4 = setA.symmetricDifference(setB)
//        print(setResult4);

        let dict:[String: String] = ["key1":"value1","key2":"value2","key3":"value3","key4":"value4"]
        //遍历key-value
        for (key, value) in dict {
            print("\(key) : \(value)")
        }

        print("––––––––––––––––––––––––––––––––––––––––––––")
        //遍历key
        for key in dict.keys {
            print("\(key)")
        }
        print("––––––––––––––––––––––––––––––––––––––––––––")
        //遍历value
        for (value) in dict.values {
            print("\(value)")
        }

        //字典可以排序
//        dict.sorted { ((>, >)) -> Bool in
//
//        }

    }

    //闭包练习
    //枚举练习
    class func enumTest() {
        //语法
        //关联值
    
    }

    func scrollLayer() {
        let layer = CALayer()
        layer.contents = UIImage.init(named: "")?.cgImage
        layer.frame = UIScreen.main.bounds

        let scrollLayer = CAScrollLayer()
        scrollLayer.frame = UIScreen.main.bounds
        scrollLayer.addSublayer(layer)
    }

}
